<%-- 
    Document   : ViewProduct
    Created on : Mar 29, 2012, 4:57:53 AM
    Author     : Tokino
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.CallableStatement"%>
<%@page import="dbhandler.DBConnector"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1" />
        <META Http-Equiv="Cache-Control" Content="no-cache"/>
        <META Http-Equiv="Cache-Control" Content="no-store"/>
        <META Http-Equiv="Pragma" Content="no-cache"/>
        <META Http-Equiv="Expires" Content="0"/>

        <%
            response.setHeader("Cache-Control", "no-cache, must-revalidate, no-store");
            response.setHeader("Pragma", "no-cache");
            response.setDateHeader("Expires", 0);

        %>

        <link rel="stylesheet" href="../css/style.css" type="text/css" id="" media="print, projection, screen" />
        <script type="text/javascript" src="../script/jquery-latest.js"></script>
        <script type="text/javascript" src="../script/jquery.tablesorter.js"></script>
        <script type="text/javascript" src="../script/jquery.tablesorter.pager.js"></script>

        <script type="text/javascript">
            $(document).ready(function() {
                // call the tablesorter plugin
                $("table").tablesorter({
                    // sort on the first column and third column, order asc
                    sortList: [[1,0]],
                    headers: {

                    }
                    ,
                    widthFixed: true, widgets: ['zebra']
                })
                .tablesorterPager({container: $("#pager")});
                ;
            });


        </script>
    </head>
    <link rel="stylesheet" href="../style/style.css" type="text/css" id="" media="print, projection, screen" />
    <jsp:useBean id="SecprogScopeSession" class=
                 "servlets.SecprogScopeSession" scope="session" />
    <%
        if (SecprogScopeSession.getAccounttype() == 3 || SecprogScopeSession.getAccounttype() == 4 || SecprogScopeSession.getAccounttype() == 5 || SecprogScopeSession.getAccounttype() == 6) {
            response.sendRedirect("../product/PMain.jsp");
        } else if (SecprogScopeSession.getAccounttype() == 2) {
            response.sendRedirect("../accounting/PCMain.jsp");
        } else if (SecprogScopeSession.getAccounttype() == 10) {
            response.sendRedirect("../admin/AMain.jsp");
        }
        if (!SecprogScopeSession.getIsLogin()) {
            response.sendRedirect("../index.jsp");
        }
        DBConnector dbConnectorchk = null;
        dbConnectorchk = new DBConnector("localhost", 3306, "selector", "53l3ct0r", "bookaholic");
        
        if(!dbConnectorchk.check_creditinfo(SecprogScopeSession.getUserName()))
            response.sendRedirect("ChargeDelivery.jsp");
    %>
    <body bgcolor="#FFFACD">

        <table width="94%" border="0" align="center">

            <tr >
                <td style="background-color:#FFA500; height:100px">

                </td>
            </tr>
            <tr style="background-color:#FFA500; height:30px" align="center">

                <td><a href="CMain.jsp">Home</a><font color="#FFFFFF" face="Arial">|</font>
                    <a href="ViewProduct.jsp">View Product</a><font color="#FFFFFF" face="Arial">|</font>
                    <a href=""></a><font color="#FFFFFF" face="Arial">|</font>
                    <a href="PSettings.jsp">Settings</a><font color="#FFFFFF" face="Arial">|</font>
                    <a href="../logout/LogoutProcess.jsp">Logout</a>
                </td>

            </tr>

            <tr style="background-color:#FFA500; height:30px" align="center">

                <td><a href=""> </a><font color="#FFFFFF" face="Arial">|</font>
                    <a href="ViewProduct.jsp"> </a><font color="#FFFFFF" face="Arial">|</font>
                    <a href=""> </a><font color="#FFFFFF" face="Arial">|</font>
                    <a href=""> </a>

                </td>

            </tr>


            <tr style="background-color:#FFA500; height:30px" align="center">

                <td><a50>Welcome Customer <%= SecprogScopeSession.getFullName()%><font color="#FFFFFF" face="Arial">|</font>
                Customer since <%= SecprogScopeSession.getDatecreated()%><font color="#FFFFFF" face="Arial">|</font>
                Last Login is <%= SecprogScopeSession.getLastlogin()%></a50>
        </td>

    </tr>
    <%
        String str = "";
        String button = "";
        String stat2 = "";
        SecprogScopeSession.setCviewstatus(" ");
        CallableStatement callable5 = null;
        ResultSet result5 = null;
        String authCall5 = "";
        int ctr5 = 0;
        //Connect to the DB
        dbConnectorchk.connectToDB();


        if (!(request.getParameter("bt_search") == null)) {
            button = request.getParameter("bt_search");
        }


        if (!(request.getParameter("search") == null)) {
            str = request.getParameter("search");
        }



     %>
    <tr>
        <td style="padding-top:5%; padding-left:2%; padding-right:2%; padding-bottom:5%; background-color:#EEEEEE;height:auto;width:920px;">
    <a1>Search Product</a1><br>

    <form name="searchproduct" method="post" action="">
        <table>
            <tr>
                <td><a50>Search Title</a50></td>
            <td><input type="text"  name="search" value="<%=str%>"/>
                <br></td>
            <td><a54>Enter blank to search all (1 string maximum)</a54></td>
            </tr>

            <tr>
                <td><a50><input type="submit" name="bt_search" value="Search"/></a50></td>
            <a53><%=SecprogScopeSession.getCviewstatus()%></a53><br>
            </tr>
        </table>
    </form> 



    <table  border="0" id="myTable" class="tablesorter" style="width: 100%;" align="center">
        <thead> 
            <tr> 
                <th>Num</th> 
                <th>Title</th> 
                <th>AddInfo</th> 
                <th>Category</th> 
                <th>Type</th> 
                <th>Synopsis</th> 
                <th>Price</th>
                <th>Quantity</th> 
            </tr> 
        </thead>                 
        <tfoot> 
            <tr> 
                <th>Num</th> 
                <th>Title</th> 
                <th>AddInfo</th> 
                <th>Category</th> 
                <th>Type</th> 
                <th>Synopsis</th> 
                <th>Price</th>
                <th>Quantity</th> 
            </tr> 
        </tfoot> 

        <tbody> 
            <%
            
                  if (str.equals("")) {
            authCall5 = "{ call search_product_all() }";
            SecprogScopeSession.setCviewstatus("Valid");
            ctr5 = 1;
callable5 = dbConnectorchk.getConnection().prepareCall(authCall5);
             result5 = callable5.executeQuery();


                while (result5.next()) {
                    %>
            <tr> 
                <td><%=result5.getInt("colid")%></td>
                <td><%=result5.getString("title")%></td>
                <td><%=result5.getString("addinfo")%></td>
                <td><%=result5.getString("category")%></td>
                <td><%=result5.getString("type")%></td>
                <td><%=result5.getString("synopsis")%></td>
                <td><%=result5.getString("price")%></td>
            <%
                    System.out.println(result5.getString("title"));
                
            }          
            
        } else if (!str.matches("(?=^.{1,}$)(?=[a-zA-Z0-9]*)(?!.*[\\,\\.\\-\\s\\!\\;\\:\\\"\\<\\>\\(\\)\\{\\}\\[\\]\\@\\#\\$\\%\\^\\`\\~\\=\\|\\/\\\\\\x00-\\x1F]).*$")) {
            System.out.println("yehey");
            SecprogScopeSession.setCviewstatus("Please enter a valid string ");
            str = "";
            ctr5=1;
        } else {
            authCall5 = "{ call search_product(?) }";
            SecprogScopeSession.setCviewstatus("Valid");
            callable5 = dbConnectorchk.getConnection().prepareCall(authCall5);
            callable5.setString(1, str);
 
            result5 = callable5.executeQuery();


                while (result5.next()) {
                    System.out.println(result5.getString("title"));
                                        %>
            <tr> 
                <td><%=result5.getInt("colid")%></td>
                <td><%=result5.getString("title")%></td>
                <td><%=result5.getString("addinfo")%></td>
                <td><%=result5.getString("category")%></td>
                <td><%=result5.getString("type")%></td>
                <td><%=result5.getString("synopsis")%></td>
                <td><%=result5.getString("price")%></td>
            <%
                
            }
        }


            %>


                <%          
                    dbConnectorchk.disconnectDB();
                %>


        </tbody> 
    </table> 
    <div id="pager" class="pager" align="left" style=" height: auto; width: 95%;">
        <form>
            <img src="addons/pager/icons/first.png" class="first"/>
            <img src="addons/pager/icons/prev.png" class="prev"/>
            <input readonly="readonly" type="text" class="pagedisplay"/>
            <img src="addons/pager/icons/next.png" class="next"/>
            <img src="addons/pager/icons/last.png" class="last"/>
            <select class="pagesize">
                <option selected="selected"  value="10">10</option>

                <option value="20">20</option>
                <option value="30">30</option>
                <option  value="40">40</option>
            </select>
        </form>
    </div>
    <br>
    <br>


    username is <%= SecprogScopeSession.getUserName()%>
    Session  is <%= SecprogScopeSession.getIsLogin()%>
    accounttype  is <%= SecprogScopeSession.getAccounttype()%>
    Session  is <%= SecprogScopeSession.getSessionid()%>

    </td>
    </tr>

    <tr>
        <td colspan="2" style="background-color:#FFA500;text-align:center;">
            Copyright © 2011</td>
    </tr>
</table>

</body>
</html> 